package com.ruoyi.system.service.zhaungxiuservice.shopService.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderAfterSale;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.ProductInfo;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.SupplierInfo;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.zhuangxiumapper.orderformMapper.OrderAfterSaleMapper;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.ProductInfoMapper;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.SupplierInfoMapper;
import com.ruoyi.system.service.zhaungxiuservice.shopService.OrderAfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 售后管理Service业务层处理
 * 
 * @author 张少丛
 * @date 2020-11-05
 */
@Service
public class OrderAfterSaleServiceImpl implements OrderAfterSaleService
{
    @Autowired
    private OrderAfterSaleMapper orderAfterSaleMapper;

    @Autowired
    private SupplierInfoMapper supplierInfoMapper;

    @Autowired
    private ProductInfoMapper productInfoMapper;

    /**
     * 查询售后管理
     * 
     * @param afterSaleId 售后管理ID
     * @return 售后管理
     */
    @Override
    public OrderAfterSale selectOrderAfterSaleById(Long afterSaleId)
    {
        return orderAfterSaleMapper.selectOrderAfterSaleById(afterSaleId);
    }

    /**
     * 查询售后管理列表
     * 
     * @param orderAfterSale 售后管理
     * @return 售后管理
     */
    @Override
    public List<OrderAfterSale> selectOrderAfterSaleList(OrderAfterSale orderAfterSale,Long userId)
    {
        SupplierInfo supplierInfo = new SupplierInfo();
        supplierInfo.setCustomerId(userId);
        supplierInfo.setSupplierTypeform(2);
        // 创建集合储存供应商ID
        List<Long> supplierIds = new ArrayList<Long>();
        // 创建集合储存商品ID
        List<Long> productInfoIds = new ArrayList<Long>();
        // 根据用户ID查询供应商信息
        List<SupplierInfo> supplierInfoList = supplierInfoMapper.selectSupplierInfoByUserId(supplierInfo);
        if(supplierInfoList.size()>0){
            for (SupplierInfo supplier : supplierInfoList) {
                supplierIds.add(Long.valueOf(supplier.getSupplierId()));
            }
        }else{
            supplierIds.add(Long.valueOf(-1));
        }
        List<ProductInfo> productInfoList = productInfoMapper.selectInfoBySuppliers(supplierIds);
        if(productInfoList.size() > 0){
            for (ProductInfo productInfo : productInfoList) {
                productInfoIds.add(Long.valueOf(productInfo.getProductId()));
            }
        }else{
            productInfoIds.add(Long.valueOf(-1));
        }
        orderAfterSale.setProductInfoIds(productInfoIds);
        return orderAfterSaleMapper.selectOrderAfterSaleList(orderAfterSale);
    }

    /**
     * 新增售后管理
     * 
     * @param orderAfterSale 售后管理
     * @return 结果
     */
    @Override
    public int insertOrderAfterSale(OrderAfterSale orderAfterSale)
    {
        return orderAfterSaleMapper.insertOrderAfterSale(orderAfterSale);
    }

    /**
     * 修改售后管理
     * 
     * @param orderAfterSale 售后管理
     * @return 结果
     */
    @Override
    public int updateOrderAfterSale(OrderAfterSale orderAfterSale)
    {
        return orderAfterSaleMapper.updateOrderAfterSale(orderAfterSale);
    }

    /**
     * 批量删除售后管理
     * 
     * @param afterSaleIds 需要删除的售后管理ID
     * @return 结果
     */
    @Override
    public int deleteOrderAfterSaleByIds(Long[] afterSaleIds)
    {
        return orderAfterSaleMapper.deleteOrderAfterSaleByIds(afterSaleIds);
    }

    /**
     * 删除售后管理信息
     * 
     * @param afterSaleId 售后管理ID
     * @return 结果
     */
    @Override
    public int deleteOrderAfterSaleById(Long afterSaleId)
    {
        return orderAfterSaleMapper.deleteOrderAfterSaleById(afterSaleId);
    }
}
